Haptic: Haptic Feedback

更新时间:
2025-01-13

Haptic: Haptic Feedback

This haptic module provides functions related to device haptic feedback. By calling different methods, you can trigger various types of haptic feedback effects.

Developers can determine whether this interface work in the EdgerOS mobile App environment through the following code:

edger.env().then(data => {
  if (data.env === 'edgerapp') {
    // We work in EdgerOS mobile App environment.
  }
}).catch(error => {
  console.error(error);
});

Functions

edger.haptic.impactMedium()

Trigger a medium-intensity haptic feedback.

Example

edger.haptic.impactMedium().then(() => {
  console.log("haptic response successful");
}).catch((error) => {
  console.error(error);
});

async / await

async function impactMedium() {
  try {
    await edger.haptic.impactMedium();
  } catch (error) {
    console.error(error);
  }
}

edger.haptic.impactHeavy()

Trigger a high-intensity haptic feedback.

Example

edger.haptic.impactHeavy().then(() => {
  console.log("haptic response successful");
}).catch((error) => {
  console.error(error);
});

async / await

async function impactHeavy() {
  try {
    await edger.haptic.impactHeavy();
  } catch (error) {
    console.error(error);
  }
}

edger.haptic.impactLight()

Trigger a low-intensity haptic feedback.

Example

edger.haptic.impactLight().then(() => {
  console.log("haptic response successful");
}).catch((error) => {
  console.error(error);
});

async / await

async function impactLight() {
  try {
    await edger.haptic.impactLight();
  } catch (error) {
    console.error(error);
  }
}

edger.haptic.impactTick()

Trigger a short haptic feedback, typically used for confirming action.

Example

edger.haptic.impactTick().then(() => {
  console.log("haptic response successful");
}).catch((error) => {
  console.error(error);
});

async / await

async function impactTick() {
  try {
    await edger.haptic.impactTick();
  } catch (error) {
    console.error(error);
  }
}

edger.haptic.vibrate()

Trigger the device to vibrate.

Example

edger.haptic.vibrate().then(() => {
  console.log("haptic response successful");
}).catch((error) => {
  console.error(error);
});

async / await

async function vibrate() {
  try {
    await edger.haptic.vibrate();
  } catch (error) {
    console.error(error);
  }
}
文档内容是否对您有所帮助?
有帮助
没帮助